123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 'use client'
- import React, { useState } from 'react'
- import dayjs from 'dayjs'
- import quarterOfYear from 'dayjs/plugin/quarterOfYear'
- import { useTranslation } from 'react-i18next'
- import type { PeriodParams } from '@/app/components/app/overview/appChart'
- import { AvgResponseTime, AvgSessionInteractions, AvgUserInteractions, ConversationsChart, CostChart, EndUsersChart, MessagesChart, TokenPerSecond, UserSatisfactionRate, WorkflowCostChart, WorkflowDailyTerminalsChart, WorkflowMessagesChart } from '@/app/components/app/overview/appChart'
- import type { Item } from '@/app/components/base/select'
- import { SimpleSelect } from '@/app/components/base/select'
- import { TIME_PERIOD_LIST } from '@/app/components/app/log/filter'
- import { useStore as useAppStore } from '@/app/components/app/store'
- dayjs.extend(quarterOfYear)
- const today = dayjs()
- const queryDateFormat = 'YYYY-MM-DD HH:mm'
- export type IChartViewProps = {
- appId: string
- }
- export default function ChartView({ appId }: IChartViewProps) {
- const { t } = useTranslation()
- const appDetail = useAppStore(state => state.appDetail)
- const isChatApp = appDetail?.mode !== 'completion' && appDetail?.mode !== 'workflow'
- const isWorkflow = appDetail?.mode === 'workflow'
- const [period, setPeriod] = useState<PeriodParams>({ name: t('appLog.filter.period.last7days'), query: { start: today.subtract(7, 'day').startOf('day').format(queryDateFormat), end: today.endOf('day').format(queryDateFormat) } })
- const onSelect = (item: Item) => {
- if (item.value === 'all') {
- setPeriod({ name: item.name, query: undefined })
- }
- else if (item.value === 0) {
- const startOfToday = today.startOf('day').format(queryDateFormat)
- const endOfToday = today.endOf('day').format(queryDateFormat)
- setPeriod({ name: item.name, query: { start: startOfToday, end: endOfToday } })
- }
- else {
- setPeriod({ name: item.name, query: { start: today.subtract(item.value as number, 'day').startOf('day').format(queryDateFormat), end: today.endOf('day').format(queryDateFormat) } })
- }
- }
- if (!appDetail)
- return null
- return (
- <div>
- <div className='flex flex-row items-center mt-8 mb-4 text-gray-900 text-base'>
- <span className='mr-3'>{t('appOverview.analysis.title')}</span>
- <SimpleSelect
- items={TIME_PERIOD_LIST.map(item => ({ value: item.value, name: t(`appLog.filter.period.${item.name}`) }))}
- className='mt-0 !w-40'
- onSelect={onSelect}
- defaultValue={7}
- />
- </div>
- {!isWorkflow && (
- <div className='grid gap-6 grid-cols-1 xl:grid-cols-2 w-full mb-6'>
- <ConversationsChart period={period} id={appId} />
- <EndUsersChart period={period} id={appId} />
- </div>
- )}
- {!isWorkflow && (
- <div className='grid gap-6 grid-cols-1 xl:grid-cols-2 w-full mb-6'>
- {isChatApp
- ? (
- <AvgSessionInteractions period={period} id={appId} />
- )
- : (
- <AvgResponseTime period={period} id={appId} />
- )}
- <TokenPerSecond period={period} id={appId} />
- </div>
- )}
- {!isWorkflow && (
- <div className='grid gap-6 grid-cols-1 xl:grid-cols-2 w-full mb-6'>
- <UserSatisfactionRate period={period} id={appId} />
- <CostChart period={period} id={appId} />
- </div>
- )}
- {!isWorkflow && isChatApp && (
- <div className='grid gap-6 grid-cols-1 xl:grid-cols-2 w-full mb-6'>
- <MessagesChart period={period} id={appId} />
- </div>
- )}
- {isWorkflow && (
- <div className='grid gap-6 grid-cols-1 xl:grid-cols-2 w-full mb-6'>
- <WorkflowMessagesChart period={period} id={appId} />
- <WorkflowDailyTerminalsChart period={period} id={appId} />
- </div>
- )}
- {isWorkflow && (
- <div className='grid gap-6 grid-cols-1 xl:grid-cols-2 w-full mb-6'>
- <WorkflowCostChart period={period} id={appId} />
- <AvgUserInteractions period={period} id={appId} />
- </div>
- )}
- </div>
- )
- }
|